

	/*******************************************************************************
*   			Impacts of a Large-Scale Parenting Program: 				   *
*					Experimental Evidence from Chile						   *
********************************************************************************


	REQUIRES:	"${dt_final}baseline_for figures.dta"
	CREATES:	${out_tables}/T3A_basebalance_ef.xls
				
	WRITEN BY:  Italo Lopez  [italolop@usc.edu]

********************************************************************************
	Prepare data
*******************************************************************************/

	* Load data
	use "$dt_int/baseline_for figures.dta", clear


	* Establish macros for regressions



/*******************************************************************************
Table A3: Baseline Balance: Executive function performance
*******************************************************************************/
	* Rename relevant variables
	*---------------------------------

	
	gen Evalplsivtot3=. 
    replace Evalplsivtot3=1 if t_per<=2 & t_per!=.
    replace Evalplsivtot3=2 if inrange(t_per,3,15) & t_per!=.
	replace Evalplsivtot3=3 if t_per>=16 & t_per!=.
	gen Evalplsivaud3=. 
    replace Evalplsivaud3=1 if  percentil_aud<=2 & t_per!=.
    replace Evalplsivaud3=2 if inrange( percentil_aud,3,15) & t_per!=.
	replace Evalplsivaud3=3 if  percentil_aud>=16 & t_per!=.
	gen Evalplsivexp3=. 
    replace Evalplsivexp3=1 if  percentil_e<=2 & t_per!=.
    replace Evalplsivexp3=2 if inrange( percentil_e,3,15) & t_per!=.
	replace Evalplsivexp3=3 if  percentil_e>=16 & t_per!=.
	tabulate Evalplsivtot3, g(plst)
	tabulate Evalplsivaud3, g(plsa)
	tabulate Evalplsivexp3, g(plse)
	g t_score_rec=ss_audi_PLSIV if t_per!=.
	g t_score_exp=ss_expre_PLSIV if t_per!=.

	* CBCL
	tabstat  ach_ttot, by(TIPO) s(mean sd)
	tabstat  ach_tint, by(TIPO) s(mean sd)
	tabstat  ach_text, by(TIPO) s(mean sd)

	tabulate ach_tot_3lev, g(acht)
	tabulate ach_int_3lev, g(achi)
	tabulate ach_ext_3lev, g(ache)

	*DCCS
	forvalues i=3/6 {

	g DCCSPunt`i'=DCCSPunt_old if  edadtramos==`i'
	g DCCS_pass`i'=DCCS_pass_old if  edadtramos==`i'
	tabulate DCCS_pass`i', g(dccs`i')

	}




iebaltab DCCSPunt3 dccs3*, grpvar(TIPO) save("${out_tables}/appendix/T3A_basebalance_ef1.xlsx") ftest fmissok pttest pftest total replace
iebaltab DCCSPunt4 dccs4*, grpvar(TIPO) save("${out_tables}/appendix/T3A_basebalance_ef2.xlsx") ftest fmissok pttest pftest total replace
iebaltab DCCSPunt5 dccs5*, grpvar(TIPO) save("${out_tables}/appendix/T3A_basebalance_ef3.xlsx") ftest fmissok pttest pftest total replace
iebaltab DCCSPunt6 dccs6*, grpvar(TIPO) save("${out_tables}/appendix/T3A_basebalance_ef4.xlsx") ftest fmissok pttest pftest total replace


import excel using "${out_tables}/appendix/T3A_basebalance_ef1.xlsx", clear
tempfile  table1 
save `table1'

import excel using "${out_tables}/appendix/T3A_basebalance_ef2.xlsx", clear
tempfile  table2
save `table2'

import excel using "${out_tables}/appendix/T3A_basebalance_ef3.xlsx", clear
tempfile  table3
save `table3'

import excel using "${out_tables}/appendix/T3A_basebalance_ef4.xlsx", clear
tempfile  table4
save `table4'

use 	`table1'
append using  `table2'
append using  `table3'
append using  `table4'

gen row = _n 
replace A = "24-35 months: Score" if row == 4
replace A = "Fail to pass pre-stage (%)" if row == 6 
replace A = "Altered (%)" if row == 8 
replace A = "Normal (%)" if row == 10

	
replace A = "36-47 months: Score" if row == 20
replace A = "Fail to pass pre-stage (%)" if row == 22
replace A = "Altered (%)" if row == 24
replace A = "Normal (%)" if row == 26
	
replace A = "48-59 months: Score" if row == 36
replace A = "Fail to pass pre-stage (%)" if row == 38
replace A = "Altered (%)" if row == 40
replace A = "Normal (%)" if row == 42

replace A = "60-72 months: Score" if row == 52
replace A = "Fail to pass pre-stage (%)" if row == 54
replace A = "Altered (%)" if row == 56
replace A = "Normal (%)" if row == 58


drop L row

export  excel using "${out_tables}/appendix/T3A_basebalance_ef.xlsx", replace

erase "${out_tables}/appendix/T3A_basebalance_ef4.xlsx"
erase "${out_tables}/appendix/T3A_basebalance_ef3.xlsx"
erase "${out_tables}/appendix/T3A_basebalance_ef2.xlsx"
erase "${out_tables}/appendix/T3A_basebalance_ef1.xlsx"

